# -*- coding: utf-8 -*-
from odoo import api, fields, models, _


class TravelAgency(models.Model):
    _name = 'tour.travel.partner'
    _inherit = 'res.partner'
    _table = 'res_partner'

    sex = fields.Selection(selection=[('male', u'男'), ('female', u'女')], string=u'性别')
    nation = fields.Selection(string=u'民族', selection='_selection_nation')
    id_card_no = fields.Char(string=u'身份证号码', size=18)
    id_card_img = fields.Char(string=u'身份证照')  # 网络url
    mobile = fields.Char(string=u'手机号码', size=11)
    phone = fields.Char(string=u'紧急备用号码', size=11)
    wx_openid = fields.Char(string=u'微信号')
    birthday = fields.Date(string=u'生日')
    state = fields.Selection([('draft', u'未认证'),
                              ('to approve', u'已申请'),
                              ('disapprove', u'拒绝'),
                              ('done', u'已认证')], string=u'状态')
    role = fields.Selection([('agency', u'用户'), ('owner', u'车主'), ('driver', u'司机')])

    @api.multi
    def _selection_nation(self):
        res_type = []
        term_list = self.env['ir.config_parameter'].search([('key', 'like', 'nation_')])
        for item in term_list:
            res_type.append((item.key[9:], _(item.value)))

        return res_type


class TravelAgency(models.Model):
    """旅行社
    customer为True
    """
    _name = 'tour.travel.agency'
    _description = u'用户'
    _inherit = 'tour.travel.partner'
    _table = 'res_partner'

    agency_level = fields.Integer(string=u'星级')

    @api.model
    def create(self, values):
        result = super(TravelAgency, self).create(values)
        result.role = 'agency'
        return result

    @api.multi
    def action_approve(self):
        for agency in self:
            if agency.state == 'to approve':
                agency.state = 'done'

    @api.multi
    def action_disapprove(self):
        for agency in self:
            if agency.state == 'to approve':
                agency.state = 'disapprove'
